<template>
  <div>
    <el-button @click="exportExcel">导出</el-button>
  </div>
</template>
<script>
import { utils, writeFileXLSX } from 'xlsx'
export default {
  name: 'ExportExcel',
  data() {
    return {
      columnsTitle: this.columns,
    }
  },
  props: ['dataSource', 'columns'],
  methods: {
    exportExcel() {
      // 创建一个工作表
      const worksheet = utils.json_to_sheet([...this.dataSource])
      // 创建一个新的工作簿
      const workbook = utils.book_new()
      // 把工作表添加到工作簿
      utils.book_append_sheet(workbook, worksheet, 'Data')
      // 改写表头
      utils.sheet_add_aoa(worksheet, [[...this.columnsTitle]], { origin: 'A1' })
      writeFileXLSX(workbook, '媒体生成人群包上传模板.xlsx')
    },
  },
  created() {},
  mounted() {},
}
</script>
<style lang="scss" scoped></style>
